import {
  addDiscuss
} from '../../../utils/api.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    addDis: {
      token: "",
      active_id: "",
      content: "",
      puserid: "",
      pusername: "", 
      puserimg: "",
      orderID:''
    },
    title:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    let addDisActive_id ="addDis.active_id"
    let addDisPuserid = "addDis.puserid"
    let addDisOrderID = "addDis.orderID"
    that.setData({
      [addDisActive_id]: options.active_id,
      [addDisPuserid]: options.user_id,
      [addDisOrderID]: options.orderID
    })
    wx.getUserInfo({
      success: function(res) {
        let addDispusername = "addDis.pusername";
        let addDispuserimg = "addDis.puserimg";
        that.setData({
          [addDispusername]: res.userInfo.nickName,
          [addDispuserimg]: res.userInfo.avatarUrl
        })
      }
    })
    wx.getStorage({
      key: 'token',
      success: function(res) {
        let addDisToken = "addDis.token";
        that.setData({
          [addDisToken]: res.data
        })
      },
    })
  },
  //评论内容  
  titleBlur: function (e) {
    let content = 'addDis.content';
    this.setData({
      [content]: e.detail.value
    })
  },
  discussBtn(){
    addDiscuss(this.data.addDis).then(res => {
      if( res.code==125){
       wx.showToast({
         title:res.msg,
         duration: 5000,
         success:function(){
           wx.switchTab({
             url: '../../personal/personal',
           })         
         }
       })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
      
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})